package com.zst.bluetooth.task;

import com.zst.bluetooth.utils.BlueException;
import com.zst.bluetooth.utils.BlueToothUtils;
import com.zst.bluetooth.utils.TaskInfo;

/**
 * Created by zhang on 2016/3/19 0019.
 */
public class OpenBlueTask extends Thread {
    private String addr = "";
    private TaskInfo info;

    public OpenBlueTask(String addr) {
        this.addr = addr;
    }

    @Override
    public void run() {
        try {
            if (BlueToothUtils.open(addr))
                info.onFinish("success");
            else
                info.onFinish("fail");
        } catch (BlueException e) {
            info.onFinish(e.getMessage());
        }
        super.run();
    }

    public void setTaskInfo(TaskInfo info) {
        this.info = info;
    }

    @Override
    public synchronized void start() {
        if (null != info)
            info.onPre();
        super.start();
    }
}
